//chainmine.txt - Part of a chain of mines. It just sits there and can be disarmed.
//  It goes off when a trigmine object sends it message 105. 
//Cell 0 - Difficulty of trap ... the total tool use needed to disarm.
//Cell 1 - The effect created.
//  0 - fiery boom (1-6 dam/level)
//  1 - magical boom (1-8 dam/level)
//  2 - spray acid (1-2 pts/level)
//  3 - spray poison (1-2 pts/level)
//  4 - spawn creature (damage is spawn #, not in game #)
//  5 - debuff shield/bless
//  6 - debuff slow
//Cell 2 - The damage of the trap. Should be roughly equal to the level of 
//  the character you want to kill with it. Defaults to 6.
//  If the mine spawns a creature, this is the town roster of the creature (not in game #).

beginobjectscript; 

variables;
short disarmed = 0;
short exploded = 0;
short near_char;
short r1;
short cur_tick;
short trap_level = 6;

body;

beginstate INIT_STATE;
	cur_tick = get_current_tick();
	sf(10,get_memory_cell(1),0);
	
	break;

beginstate DEAD_STATE;

break;

beginstate START_STATE; // door closed, waiting
	if (gf(10,get_memory_cell(1)) == 0)
		end();
	if (get_nearest_party_char(12) < 0)
		end();
		
	near_char = 4;
	if (is_combat())
		near_char = 1;
		
	if (tick_difference(cur_tick,get_current_tick()) > near_char) {
		cur_tick = get_current_tick();
		r1 = get_ran(16,1,8);
		run_sparkles_on_object(ME,162,1,4);
		create_missile_spiral(155,40,8,2);
		damage_nearby(r1,8,1,2);
		}

break;

beginstate USE_STATE;
	begin_talk_mode(get_memory_cell(0));
break;